package com.sky.common.endpoint;

import com.sky.business.sys.domain.CameraConfig;
import com.sky.common.endpoint.matcher.CameraTrackMatcher;
import com.sky.common.endpoint.matcher.DistanceAngleCameraTrackMatcher;
import com.sky.common.endpoint.sort.DistanceTrackAbilitySorter;
import com.sky.common.endpoint.sort.TrackAbilitySorter;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 设备选择器
 */
@Service
public class CameraSelector {


    /**
     * 设备是否具有跟踪能力判断
     */
    private  static CameraTrackMatcher cameraTrackMatcher = new DistanceAngleCameraTrackMatcher();

    /**
     * 排序器
     */
    private static TrackAbilitySorter sorter = new DistanceTrackAbilitySorter();


    /**
     * 选择最合适的跟踪设备
     * @param cameraConfigList 备选设备列表
     * @param uavLng 无人经经度
     * @param uavLat 无人机维度
     * @param uavAltitude 无人机海拔
     * @return 跟踪设备
     */
    public List<CameraConfig> selectTrackDevice(List<CameraConfig> cameraConfigList, double uavLng, double uavLat, double uavAltitude){
        List<CameraConfig> trackEnabledCameraList = new ArrayList<>();
        for(CameraConfig cameraConfig:cameraConfigList){
            boolean matched = cameraTrackMatcher.match(cameraConfig,uavLng,uavLat,uavAltitude);
            if(matched){
                trackEnabledCameraList.add(cameraConfig);
            }
        }
        if(trackEnabledCameraList.size()>1){
            trackEnabledCameraList = sorter.sort(trackEnabledCameraList,uavLng,uavLat,uavAltitude);
        }
        return  trackEnabledCameraList;
    }

}
